const videoRouter = require('express').Router()
const videoController = require('../constrollers/video')
const multer = require('multer')
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, 'uploads/videos/')
  },
  filename: function (req, file, cb) {
    var fileFormat = (file.originalname).split(".");
    cb(null, Date.now()+ "." + fileFormat[fileFormat.length - 1]);
  }
})
const upload = multer({ storage: storage })

// 获取视频：分页
videoRouter.get('/api/videos',videoController.getPageVideos)
// 上传视频
videoRouter.post('/upload/video',upload.array('videoFiles'),videoController.uploadVideo)
// 点赞视频
videoRouter.post('/like/video/:id',videoController.likeVideo)
// 取消点赞视频
videoRouter.post('/unlike/video/:id',videoController.unlikeVideo)
// 获取点赞视频记录
videoRouter.get('/like/videos',videoController.getLikeVideos)
// 收藏视频
videoRouter.post('/collect/video/:id',videoController.collectVideo)
// 取消收藏视频
videoRouter.post('/uncollect/video/:id',videoController.uncollectVideo)
// 获取收藏视频记录
videoRouter.get('/collect/videos',videoController.getCollectVideos)
// 搜索视频
videoRouter.get('/api/search/:kw',videoController.selectVideosByKw)
// 获取用户发布、点赞、收藏的视频
videoRouter.get('/user/videos/',videoController.selectVideosOfUser)
// 获取作家主页数据
videoRouter.get('/api/author/:id', videoController.getAuthorData)

module.exports = videoRouter